﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tycho.Runtime;

namespace Tycho.Peyote {
    /// <summary>
    /// Interaction logic for InteractivePromptGlyph.xaml
    /// </summary>
    public partial class InteractivePromptGlyph : GlyphControl {
        Environment Environment;
        public override AnyObject RuntimeValue {
            get { return RuntimeModule.Null; }
        }

        public override GlyphHandle GlyphHandle { get; set; }

        public InteractivePromptGlyph (Environment environment) {
            InitializeComponent ();

            Environment = environment;
        }

        private void SourceTextBox_PreviewKeyDown (object sender, KeyEventArgs e) {
            if (e.Key == Key.Enter && Keyboard.Modifiers == ModifierKeys.None) {
                AnyObject result = ResultObject.Create(SourceTextBox.Text, Environment.TopLevel);
                var glyph = new InteractiveResultGlyph (SourceTextBox.Text, Environment);
                Environment.Layout.PlaceGlyph (new GlyphHandle (glyph, new GlyphOptions (Environment), Environment), GlyphHandle);
                SourceTextBox.Text = "";
                e.Handled = true;
            }
        }
    }
}
